package com.solidumgame.martillo.level
{
	import com.pblabs.engine.PBE;
	import com.pblabs.engine.entity.EntityComponent;
	import com.solidumgame.martillo.score.events.ScoreGenericEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import com.solidumgame.martillo.level.event.LevelGenericEvent;
	import com.solidumgame.martillo.level.event.LevelGenericEvent;

	
	public class Level extends EntityComponent
	{
		protected var level:Number;
	
		public function Level()
		{
			PBE.mainStage.addEventListener(ScoreGenericEvent.SCORE_UPDATED_EVENT,updateSpeed);			
		}
		override protected function onAdd():void{
			super.onAdd();
			PBE.mainStage.addEventListener(ScoreGenericEvent.SCORE_UPDATED_EVENT,updateSpeed);
		}
		
		override protected function onRemove():void{
			super.onRemove();
			PBE.mainStage.addEventListener(ScoreGenericEvent.SCORE_UPDATED_EVENT,updateSpeed);
		}
		
		protected function updateSpeed(e:ScoreGenericEvent):void{
			
			this.level = e.score;
			//trace("Desde el level",level);
			PBE.mainStage.dispatchEvent(new LevelGenericEvent(LevelGenericEvent.UPDATE_EVENT,level));
			
		}
		
	}
}